import { request } from '@/api/service'

export const crudOptions = vm => {
  return {
    pageOptions: {
      compact: true
    },
    options: {
      tableType: 'vxe-table',
      rowKey: true, // 必须设置，true or false
      rowId: 'id',
      height: '100%', // 表格高度100%, 使用toolbar必须设置
      highlightCurrentRow: false
    },
    rowHandle: {
      width: 180,
      view: {
        thin: true,
        text: '',
        disabled () {
          return !vm.hasPermissions('Retrieve')
        }
      },
      edit: {
        thin: true,
        text: '',
        disabled () {
          return !vm.hasPermissions('Update')
        }
      },
      remove: {
        thin: true,
        text: '',
        disabled () {
          return !vm.hasPermissions('Delete')
        }
      },
      custom: [
        {
          thin: true,
          text: '',
          title: '实时数据',
          size: 'small',
          type: 'warning',
          icon: 'el-icon-location',
          show (index, row) {
            return row.vehicle_status === 1
          },
          emit: 'openRealInfo'
        }
      ]
    },
    indexRow: {
      // 或者直接传true,不显示title，不居中
      title: '序号',
      align: 'center',
      width: 100
    },
    viewOptions: {
      componentType: 'form'
    },
    formOptions: {
      defaultSpan: 24, // 默认的表单 span
      width: '35%'
    },
    columns: [{
      title: 'ID',
      key: 'id',
      show: false,
      disabled: true,
      width: 90,
      form: {
        disabled: true
      }
    },
    {
      title: 'VIN',
      key: 'search',
      show: false,
      disabled: true,
      search: {
        disabled: false
      },
      form: {
        disabled: true,
        component: {
          placeholder: '请输入关键词'
        }
      },
      view: {
        disabled: true
      }
    },
    {
      title: '车辆VIN',
      key: 'vin',
      treeNode: true,
      type: 'input',
      form: {
        editDisabled: true,
        rules: [
          // 表单校验规则
          { required: true, message: '车辆VIN必填' }
        ],
        component: {
          props: {
            clearable: true
          },
          placeholder: '请输入车辆VIN'
        },
        itemProps: {
          class: { yxtInput: true }
        }
      }
    },
    {
      title: '车辆类型',
      key: 'vehicle_type',
      type: 'select',
      search: {
        disabled: false
      },
      dict: {
        url: '/api/system/dictionary/' + '?limit=994&status=1',
        cache: true,
        value: 'value', // 数据字典中value字段的属性名
        label: 'label', // 数据字典中label字段的属性名
        getData: (url, dict, { form, component }) => { // 配置此参数会覆盖全局的getRemoteDictFunc
          return request({ url: url }).then(ret => {
            const responseData = ret.data.data
            return responseData.filter(data => data.code === 'vehicle_type')
          })
        }
      },
      form: {
        editDisabled: false,
        rules: [
          // 表单校验规则
          { required: true, message: '车辆类型必填' }
        ],
        component: {
          props: {
            clearable: true
          },
          placeholder: '请输入车辆类型'
        },
        itemProps: {
          class: { yxtInput: true }
        }
      }
    },
    {
      title: '电子围栏',
      key: 'vehicle_fence',
      type: 'select',
      search: {
        disabled: false
      },
      dict: {
        url: '/api/vehicle_fence/' + '?limit=994&status=0',
        cache: true,
        value: 'id', // 数据字典中value字段的属性名
        label: 'fence_name', // 数据字典中label字段的属性名
        getData: (url, dict, { form, component }) => { // 配置此参数会覆盖全局的getRemoteDictFunc
          return request({ url: url }).then(ret => {
            return ret.data.data
          })
        }
      },
      form: {
        editDisabled: false,
        rules: [
          // 表单校验规则
          { required: false}
        ],
        component: {
          props: {
            clearable: true
          },
          placeholder: '请选择围栏'
        },
        itemProps: {
          class: { yxtInput: true }
        }
      }
    },
    {
      title: '车辆状态',
      key: 'vehicle_status',
      type: 'select',
      search: {
        disabled: false
      },
      dict: {
        url: '/api/system/dictionary/' + '?limit=995&status=1',
        cache: true,
        value: 'value', // 数据字典中value字段的属性名
        label: 'label', // 数据字典中label字段的属性名
        getData: (url, dict, { form, component }) => { // 配置此参数会覆盖全局的getRemoteDictFunc
          return request({ url: url }).then(ret => {
            const responseData = ret.data.data
            return responseData.filter(data => data.code === 'vehicle_status')
          })
        }
      },
      form: {
        editDisabled: true,
        rules: [
          // 表单校验规则
          { required: true, message: '车辆状态必填' }
        ],
        component: {
          props: {
            clearable: true
          },
          placeholder: '请输入车辆状态'
        },
        itemProps: {
          class: { yxtInput: true }
        }
      }
    },
    {
      title: '电机厂商',
      key: 'vehicle_motor',
      type: 'select',
      search: {
        disabled: false
      },
      dict: {
        url: '/api/system/dictionary/' + '?limit=997&status=1',
        cache: true,
        value: 'value', // 数据字典中value字段的属性名
        label: 'label', // 数据字典中label字段的属性名
        getData: (url, dict, { form, component }) => { // 配置此参数会覆盖全局的getRemoteDictFunc
          return request({ url: url }).then(ret => {
            const responseData = ret.data.data
            return responseData.filter(data => data.code === 'vehicle_motor_factory')
          })
        }
      },
      form: {
        editDisabled: false,
        rules: [
          // 表单校验规则
          { required: true, message: '电机厂商必填' }
        ],
        component: {
          props: {
            clearable: true
          },
          placeholder: '请选择电机厂商'
        },
        itemProps: {
          class: { yxtInput: true }
        }
      }
    },
    {
      title: '电池厂商',
      key: 'vehicle_battery',
      search: {
        disabled: false
      },
      type: 'select',
      dict: {
        url: '/api/system/dictionary/' + '?limit=996&status=1',
        cache: true,
        value: 'value', // 数据字典中value字段的属性名
        label: 'label', // 数据字典中label字段的属性名
        getData: (url, dict, { form, component }) => { // 配置此参数会覆盖全局的getRemoteDictFunc
          return request({ url: url }).then(ret => {
            const responseData = ret.data.data
            return responseData.filter(data => data.code === 'vehicle_battery_factory')
          })
        }
      },
      form: {
        editDisabled: false,
        rules: [
          // 表单校验规则
          { required: true, message: '电池厂商必填' }
        ],
        component: {
          props: {
            clearable: true
          },
          placeholder: '请选择电池厂商'
        },
        itemProps: {
          class: { yxtInput: true }
        }
      }
    },
    {
      title: '电机编号',
      key: 'vehicle_motor_code',
      type: 'input',
      form: {
        editDisabled: false,
        component: {
          props: {
            clearable: true
          },
          placeholder: '请输入电机厂商'
        },
        itemProps: {
          class: { yxtInput: true }
        }
      }
    },
    {
      title: '起点',
      key: 'start_point',
      type: 'select',
      dict: {
        data: [{ value: "116.664053,39.531791", label: '116.664053,39.531791' }]
      },
      form: {
        editDisabled: false,
        component: {
          props: {
            clearable: true
          },
          placeholder: '请输入起点地址'
        },
        itemProps: {
          class: { yxtInput: true }
        }
      }
    },
    {
      title: '终点',
      key: 'end_point',
      type: 'select',
      dict: {
        data: [{ value: "116.671005,39.53664", label: '116.671005,39.53664' }]
      },
      form: {
        editDisabled: false,
        component: {
          props: {
            clearable: true
          },
          placeholder: '请输入终点地址'
        },
        itemProps: {
          class: { yxtInput: true }
        }
      },
    },
    {
     title: '路况情况',
     key: 'road_desc',
     type: 'select',
       form: {
         editDisabled: true,
      }
    },
    {
      title: '此路段意外风险',
      key: 'road_accident',
      type: 'select',
        form: {
          editDisabled: true,
       }
     },
    ].concat(vm.commonEndColumns({create_datetime: { showForm: false, showTable: false }}))
  }
}
